package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {
@Bean
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource dataSource){
        //1 创建SqlSessionFatoryBean对象
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    //2 设置参数
factoryBean.setDataSource(dataSource);
factoryBean.setTypeAliasesPackage("com.itheima.bean");
    //3 返回SqlSessionFatoryBean
    return factoryBean;
    }
    @Bean
    public MapperScannerConfigurer getMapperScannerConfigurer(){
    //1 创建MapperScannerConfigurer对象
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        //2 设置参数
        msc.setBasePackage("com.itheima.mapper");
        //3 返回MapperScannerConfigurer对象
        return msc;
    }
}
